import { createStore } from 'vuex'

declare let SessionStorage: any;
const USER = 'USER';

 const store = createStore({
  state: {
    // 保存登录成功的用户信息 + sessionStorage || 防止空指针
    user: SessionStorage.get(USER) || {}
  },
  actions: {
  },
  // 真正操作数据的地方
  mutations: {
   setUser(state, user) {
    state.user = user;
    // 保存到 sessionStorage
    SessionStorage.set(USER, user)
   }
  },
  getters: {
  },
  modules: {
  }
})

export default store;
